home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
yahoo
/
yahooutil.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
8KB
|
207 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from __future__ import with_statement
import re
from urllib import unquote_plus
from itertools import izip
from struct import pack, unpack, calcsize
from httplib import HTTPConnection
from yahoo.yahoolookup import ykeys, services, statuses
from logging import getLogger
log = getLogger('yahoo')
info = log.info
from util import odict, threaded, flatten, hex2bin
from pprint import pformat
from common.exceptions import LoginError
class YahooLoginError(LoginError):
def __init__(self, protocol, message):
import yahoo
if not isinstance(message, basestring):
raise TypeError('message must be a string')
self.protocol = protocol
Exception.__init__(self, message)
_filematch = re.compile('.*/(.+)\\?\\w+')
def filename_from_url(url):
return unquote_plus(_filematch.search(url).group(1))
argsep = pack('BB', 192, 128)
def to_ydict(d):
if not d:
return ''
def to_ydict_entry(k, v):
try:
n = int(k)
except ValueError:
try:
n = ykeys[k]
log.warning('to_ydict got a dict with a non number key: %s', k)
return ''
try:
v = str(v)
except UnicodeEncodeError:
v = unicode(v).encode('utf-8')
return ''.join([
str(n),
argsep,
v,
argsep])
if hasattr(d, 'iteritems'):
item_iterator = d.iteritems()
elif isinstance(d, (list, tuple)):
item_iterator = izip(d[::2], d[1::2])
return (''.join,)((lambda .0: for k, v in .0:
to_ydict_entry(k, v))(item_iterator))
def from_ydict_iter(data):
if not data:
return iter([])
data = data.split(argsep)
keys = data[::2]
values = data[1::2]
return izip(keys, values)
def format_packet(data, maxlen = 500, sensitive = False):
return pformat(items)
def yiter_to_dict(yiter):
d = odict()
for k, v in yiter:
try:
k = ykeys[k]
except KeyError:
pass
d[k] = v
return d
def from_ydict(data):
d = { }
for k, v in from_ydict_iter(data):
if k in d:
log.warning('duplicate %s: %s', k, v)
d[k] = v
return d
header_pack = '!4sHHHHII'
header_desc = (header_pack, 'ymsg', 'version', 'zero', 'size', 'service', 'status', 'session_id')
header_size = calcsize(header_pack)
def header_tostr(hdr):
try:
sv = services[hdr.service]
except KeyError:
log.error('No service string for %s', hdr.service)
sv = str(hdr.service)
try:
st = services[hdr.status]
except KeyError:
log.error('No service string for %s', hdr.status)
st = str(hdr.status)
return 'YMSG packet( srv:%s, st:%s, id:%d v:%d, sz:%d )' % (sv, st, hdr.session_id, hdr.version, hdr.size)
def yahoo_http_post(ydata, cookies, progress_cb = (lambda x: pass)):
conn = HTTPConnection('filetransfer.msg.yahoo.com')
conn._http_vsn_str = 'HTTP/1.0'
conn._http_vsn = 10
url = 'http://filetransfer.msg.yahoo.com:80/notifyft'
conn.putrequest('POST', url, skip_host = True, skip_accept_encoding = True)
conn.putheader('Content-length', str(len(ydata)))
conn.putheader('Host', 'filetransfer.msg.yahoo.com:80')
conn.putheader('Cookie', cookies)
conn.endheaders()
log.info('putting %d bytes of data...', len(ydata))
for x in xrange(0, len(ydata), 512):
conn.send(ydata)
progress_cb(x)
progress_cb(len(ydata))
response = conn.getresponse()
respdata = response.read()
status = response.status
log.info('response data %d bytes, status code %s', len(respdata), status)
conn.close()
if status != 200:
log.error('ERROR: POST returned a status of %d', status)
return False
info('HTTP POST response status %d', status)
return True
yahoo_http_post = threaded(yahoo_http_post)
class Cookie(str):
def __init__(self, s):
str.__init__(s)
info('Cookie string %s', s)
self.params = odict()
for pair in s.split('&'):
(key, val) = pair.split('=')
self.params[key] = val
def val(self):
return '&'.join((lambda .0: for k, v in .0:
'%s=%s' % (k, v))(self.params.items()))
def add_cookie(jar, cookiestr):
spl = cookiestr.find('\t')
key = cookiestr[:spl]
value = cookiestr[spl + 1:]
value = value.split('; ')[0]
log.info('adding cookie %s: %s', key, value)
jar[key] = value
def y_webrequest(url, data, cookies):
headers = {
'Cookie': cookies['Y'] + '; ' + cookies['T'],
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5)',
'Cache-Control': 'no-cache' }
req = urllib2.Request(url, data, headers)
response = urllib2.urlopen(req)
return response.read()
if __name__ == '__main__':
cookies = {
'Y': 'v=1&n=3lutd2l220eoo&l=a4l8dm0jj4hisqqv/o&p=m2l0e8v002000000&r=fr&lg=us&intl=us',
'T': 'z=3H2OGB3NLPGBQXPLeKgW24v&a=YAE&sk=DAAHHqpEue2zZY&d=YQFZQUUBb2sBWlcwLQF0aXABQldCb2lBAXp6ATNIMk9HQmdXQQ--' }
data = '<validate intl="us" version="8.1.0.209" qos="0"><mobile_no msisdn="17248406085"></mobile_no></validate>'
print y_webrequest('http://validate.msg.yahoo.com/mobileno?intl=us&version=8.1.0.209', data, cookies)